package com.csun.cmny.provider.service.impl;

import com.alibaba.fastjson.JSON;
import com.csun.cmny.base.constant.AliyunMqTopicConstants;
import com.csun.cmny.provider.model.domain.MqMessageData;
import com.csun.cmny.provider.model.dto.SendMessageRequest;
import com.csun.cmny.util.RedisKeyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-11-07 13:59
 * @Description:
 */
@Slf4j
@Component
public class OpcPushMessageProducer {

    public MqMessageData sendMessageMq(SendMessageRequest sendMessageRequest) {

        log.info("opc 发送消息. sendMessageRequest={}", sendMessageRequest);
        String msgBody;
        try {
            msgBody = JSON.toJSONString(sendMessageRequest);
        } catch (Exception e) {
            log.error("发送短信验证码 smsMessage转换为json字符串失败", e);
            throw new RuntimeException("发送消息 smsMessage转换为json字符串失败");
        }
        String topic = AliyunMqTopicConstants.MqTopicEnum.SEND_MESSAGE_TOPIC.getTopic();
        String tag = sendMessageRequest.getMsgType();
        String key = RedisKeyUtil.createMqKey(topic, tag, sendMessageRequest.getRefNo(), msgBody);

        return new MqMessageData(msgBody, topic, tag, key);
    }

}
